const infodata = {
  data: [],
  copyData: [],
};

const reducer = (state = infodata, { type, payload }: any) => {
  let newState = JSON.parse(JSON.stringify(state));
  switch (type) {
    case "GET_LIST":
      newState.data = payload;
      return newState;

    case "ADD_LIST":
      newState.data.push(payload);
      return newState;
    case "EDIT_LIST":
      newState.data.forEach((item: any, index: number) => {
        if (item.key === payload.key) {
          newState.data[index] = payload;
        }
      });
      return newState;

    default:
      return newState;
  }
};

export default reducer;
